package com.gwd.task.controller;

import com.gwd.task.model.CodeRepositoryDTO;
import com.gwd.task.model.CodeSubmitRelateDTO;
import com.gwd.task.services.CodeRepositoryServer;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhiyongming
 * @date 2020/12/22 15:11
 */
@RestController
@RequestMapping(value = "/v1/rep")
public class CodeRepositoryController {
    @Resource
    CodeRepositoryServer codeRepositoryServer;

    @GetMapping(value = "/find")
    public List<CodeRepositoryDTO> find(CodeRepositoryDTO dto) {
        return codeRepositoryServer.find(dto);
    }

    @GetMapping(value = "/getSubmit")
    public List<CodeSubmitRelateDTO> getSubmit(@RequestParam(value = "crId") Long crId) {
        return codeRepositoryServer.getSubmit(crId);
    }

    @PutMapping(value = "/board/{crId}")
    public void board(@PathVariable(value = "crId") Long crId) {
        codeRepositoryServer.board(crId);
    }

    @PostMapping(value = "/add")
    public void add(@RequestBody @Validated CodeRepositoryDTO dto) {
        codeRepositoryServer.save(dto);
    }

    @PutMapping(value = "/edit")
    public void edit(@RequestBody @Validated CodeRepositoryDTO dto) {
        codeRepositoryServer.save(dto);
    }

    @PutMapping(value = "/changeStatus/{id}")
    public void changeStatus(@PathVariable(value = "id") Long id) {
        codeRepositoryServer.changeStatus(id);
    }

}
